﻿using System;
using System.Collections.Generic;
using System.Linq;
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0102", Name = "记载规律逻辑违反", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0102:VerfityOneResult
    {        
        /// <summary>
        /// 默认的检查方式倒序
        /// </summary>
        private EnumDateSort _dataSort = EnumDateSort.Asc;

        /// <summary>
        /// 日期结果顺序
        /// 正序 倒序
        /// </summary>
        public EnumDateSort DateSort
        {
            get { return _dataSort; }
            set { _dataSort = value; } 
        }

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult  = false;

            //如果是多列，首位相接排列
            List<string> entryResults = result.SelectMany(o => o).Where(t=>EmptyResultCount(t).Equals(0)).ToList();

          
            entryResults = CompleteDate( entryResults);

            //找到录入结果中的 日期
            entryResults = entryResults.Select(t => new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, t).GetDate()).ToList();

            //for debug
            //System.Console.WriteLine(ChildImageObject.CategoryId);
            //判断日期的结果中是否有问号
            int questionMarkCount = QuestionMarkColumnCount(entryResults);
            //如果有问号 不再进行判断
            if (questionMarkCount > 0)
            {
                return false;
            }


            List<string> sortRowResult = null;
            if (this.DateSort == EnumDateSort.Asc)
            {
                sortRowResult = entryResults.OrderBy(t => t,new DateEntryResultComparer()).ToList();
            }
            else if (this.DateSort == EnumDateSort.Desc)
            {
                sortRowResult = entryResults.OrderByDescending(t => t, new DateEntryResultComparer()).ToList();
            }

            //
            //
           /* System.Console.WriteLine("after order by");
           
            foreach (var entryResult in sortRowResult)
            {

                System.Console.WriteLine(entryResult);
            }*/
 

            bresult = sortRowResult != null && !entryResults.SequenceEqual(sortRowResult );

            if ( bresult)
            {
                System.Console.WriteLine("VerfityRq0102");

            }
            //}

            return bresult;   
        }



    }
}